Fix the build
authorXimin Luo <infinity0@debian.org>
Thu, 20 Apr 2017 00:37:27 +0000 (02:37 +0200)
committerXimin Luo <infinity0@debian.org>
Thu, 20 Apr 2017 00:39:32 +0000 (02:39 +0200)
debian/TODO [deleted file]
debian/cargo-checksums-prune.py [new file with mode: 0755]
debian/cargo-vendor-pack.py [deleted file]
debian/cargo-vendor-unpack.py
debian/cargohome/config [new file with mode: 0644]
debian/make_orig_multi.sh
debian/patches/deps-adjust.patch [deleted file]
debian/patches/series
debian/rules

diff --git a/debian/TODO b/debian/TODO
deleted file mode 100644 (file)
index 6c2995e..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-The build currently fails with:
-
-[..]
-
-# Build final cargo binary and docs
-/usr/bin/make
-make[2]: Entering directory '/build/cargo-0.17.0'
-/usr/bin/rustc -V
-rustc 1.15.1
-/build/cargo-0.17.0/cargo-stage0 --version
-cargo 0.15.0 (built 2016-11-26)
-/build/cargo-0.17.0/cargo-stage0 build --target x86_64-unknown-linux-gnu --manifest-path /build/cargo-0.17.0//Cargo.toml --release  --verbose 
-warning: custom registry support via the `registry.index` configuration is being removed, this functionality will not work in the future
-    Updating registry `file:///build/cargo-0.17.0/vendor/index`
-error: no matching package named `backtrace` found (required by `error-chain`)
-location searched: registry file:///build/cargo-0.17.0/vendor/index
-version required: *
-Makefile:128: recipe for target 'cargo-x86_64-unknown-linux-gnu' failed
-
-[..]
-
-We need to fix d/cargo-vendor-pack.py and probably -unpack.py as well
diff --git a/debian/cargo-checksums-prune.py b/debian/cargo-checksums-prune.py
new file mode 100755 (executable)
index 0000000..5589799
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/bin/env python3
+
+# Copyright: 2015 The Debian Project
+# License: MIT-License or Apache-2.0
+#
+# Helper to remove removed-files from .cargo-checksum
+# TODO: rewrite to perl and add to dh-cargo, maybe?
+
+from collections import OrderedDict
+import json
+import os
+import sys
+
+def main(pkgdir):
+  os.chdir(pkgdir)
+  with open(".cargo-checksum.json") as fp:
+    sums = json.load(fp, object_pairs_hook=OrderedDict)
+  
+  oldfiles = sums["files"]
+  newfiles = OrderedDict([entry for entry in oldfiles.items() if os.path.exists(entry[0])])
+  sums["files"] = newfiles
+  
+  if len(oldfiles) > len(newfiles):
+    with open(".cargo-checksum.json", "w") as fp:
+      json.dump(sums, fp, separators=(',', ':'))
+
+if __name__ == "__main__":
+  main(sys.argv[1] if len(sys.argv) > 1 else ".")
diff --git a/debian/cargo-vendor-pack.py b/debian/cargo-vendor-pack.py
deleted file mode 100755 (executable)
index 84fab4b..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-#!/usr/bin/env python
-
-# Copyright: 2015 The Debian Project
-# License: MIT-License or Apache-2.0
-#
-# Helper to generate a crate registry from local unpacked crates
-# TODO: very bad code. It should be rewritten in perl and converted into dh_cargo
-
-import json
-import os
-import tarfile
-import string
-import pytoml
-from dulwich.repo import Repo
-import hashlib
-from collections import OrderedDict
-
-
-# TODO: hackish, at best. features need to be properly parsed
-def parse_deps(toml):
-  deps=[]
-  if 'dependencies' not in toml:
-    return deps
-  d = toml['dependencies']
-  if 'target' in toml:
-    t = toml['target']
-    if 'x86_64-unknown-linux-gnu' in t:
-      t = t['x86_64-unknown-linux-gnu']
-      if 'dependencies' in t:
-        d.update(t['dependencies'])
-  for k, v in d.iteritems():
-    opt = False
-    defa = True
-    if isinstance(v, dict):
-      opt = v.get('optional', opt)
-      v = '*'
-    i = {
-      "default_features": defa,
-      "features": [],
-      "kind": "normal",
-      "name": k,
-      "optional": opt,
-      "req": v,
-      "target": None
-    }
-    deps.append(i)
-  if 'build-dependencies' not in toml:
-    return deps
-  d = toml['build-dependencies']
-  for k, v in d.iteritems():
-    opt = False
-    defa = True
-    if isinstance(v, dict):
-      opt = v.get('optional', opt)
-      v = '*'
-    i = {
-      "default_features": defa,
-      "features": [],
-      "kind": "build",
-      "name": k,
-      "optional": opt,
-      "req": v,
-      "target": None
-    }
-    deps.append(i)
-  if 'dev-dependencies' not in toml:
-    return deps
-  d = toml['dev-dependencies']
-  for k, v in d.iteritems():
-    opt = False
-    defa = True
-    if isinstance(v, dict):
-      opt = v.get('optional', opt)
-      v = '*'
-    i = {
-      "default_features": defa,
-      "features": [],
-      "kind": "dev",
-      "name": k,
-      "optional": opt,
-      "req": v,
-      "target": None
-    }
-    deps.append(i)
-  return deps
-
-def main():
-  curdir = os.getcwd()
-  depsdir = os.path.join(curdir, "deps")
-  vendordir = os.path.join(curdir, "vendor")
-  cachedir = os.path.join(vendordir, "cache")
-  indexdir = os.path.join(vendordir, "index")
-  cargocfgdir = os.path.join(curdir, ".cargo")
-  for d in [cachedir, indexdir]:
-    if not os.path.exists(d):
-      os.makedirs(d)
-
-  indexdict = OrderedDict()
-  for crate in os.listdir(depsdir):
-    if os.path.isdir(os.path.join(depsdir, crate)) and not crate.startswith('.'):
-      (name, ver) = string.rsplit(crate, '-', 1)
-      print("Found %s ver. %s (at %s)" % (name, ver, os.path.join(depsdir, crate)))
-      destdir=(os.path.join(cachedir, name, ver))
-      os.makedirs(destdir)
-      tarcrate = os.path.join(destdir, "download")
-      tar = tarfile.open(tarcrate, "w:gz", format=tarfile.USTAR_FORMAT)
-      tar.add(os.path.join(depsdir, crate), arcname=crate)
-      tar.close()
-
-      manif = None
-      with open(os.path.join(depsdir,crate,'Cargo.toml'), 'rb') as f:
-        manif = pytoml.load(f)
-
-      nestdir = None
-      if len(name) >= 4:
-        nestdir = os.path.join(indexdir, name[0:2], name[2:4])
-      else:
-        nestdir = os.path.join(indexdir, '3', name[0])
-
-      cksum = hashlib.sha256(open(tarcrate, 'rb').read()).hexdigest()
-      indexdict[name] = OrderedDict([ 
-        ('name', name),
-        ('vers', ver),
-        ('deps', parse_deps(manif)),
-        ('features', manif.get('features',{})),
-        ('cksum', cksum),
-        ('yanked', False)
-      ])
-      if not os.path.exists(nestdir):
-        os.makedirs(nestdir)
-      with open(os.path.join(nestdir, name), 'a') as outfile:
-        json.dump(indexdict[name], outfile, sort_keys=False)
-        outfile.write('\n')
-      
-
-  configjson = {
-    'api': '',
-    'dl': "file://{0}".format(cachedir)
-  }
-  with open(os.path.join(indexdir, 'config.json'), 'w') as outfile:
-    json.dump(configjson, outfile)
-
-  p = []
-  for dirpath, _, paths in os.walk(indexdir): 
-    for f in paths:
-      p.append(os.path.relpath(os.path.join(dirpath,f), indexdir))
-  repo=Repo.init(indexdir)
-  for f in paths:
-    repo.stage(p)
-  repo.do_commit(b"Fake commit", committer=b"Cargo debhelper <pkg-rust-maintainers@lists.alioth.debian.org>")
-
-  cfg="""[registry]
-index = "file://{0}"
-"""
-  if not os.path.exists(cargocfgdir):
-    os.makedirs(cargocfgdir)
-
-  with open(os.path.join(cargocfgdir, "config"), "w") as cfgfile:
-    cfgfile.write(cfg.format(indexdir))
-
-if __name__ == "__main__":
-  main()
index 0e9f0b9c0001f94d5fe99e783c3cae996c4c3c23..1ab1406cea3d26ae2fb54aa2d8214abe11346d13 100755 (executable)
@@ -1,10 +1,10 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Copyright: 2015 The Debian Project
 # License: MIT-License or Apache-2.0
 #
 # Helper to unpack a local crate registry to original sources
-# TODO: rewrite to perl, maybe?
+# TODO: rewrite to perl and add to dh-cargo, maybe?
 
 import os
 import tarfile
diff --git a/debian/cargohome/config b/debian/cargohome/config
new file mode 100644 (file)
index 0000000..44eb42b
--- /dev/null
@@ -0,0 +1,5 @@
+[source.crates-io]
+replace-with = "dh-cargo-registry"
+
+[source.dh-cargo-registry]
+directory = "../deps"
index b15a6b2069968d828423d70444fa97c3ae507d6a..040b0c62dc649ec481456e5a2971bff2ecfdb0cf 100755 (executable)
@@ -51,6 +51,7 @@ cargo vendor --explicit-version --verbose deps
 # Unpack artifacts and clean embedded libs
 ${WORKDIR}/debian/cargo-vendor-unpack.py
 grep -v '^#' ${DEPS_FILTER} | xargs  -I% sh -c 'rm -rf deps/%'
+for i in deps/*; do ${WORKDIR}/debian/cargo-checksums-prune.py "$i"; done
 
 # Report any suspicious files
 cp -R deps deps-scan
diff --git a/debian/patches/deps-adjust.patch b/debian/patches/deps-adjust.patch
deleted file mode 100644 (file)
index 7d06c30..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-From: Luca Bruno <lucab@debian.org>
-Description: Adjust deps dependencies
- This is a workaround for bugs in the embedding script
-Forwarded: not-needed
-
---- a/deps/tar-0.4.9/Cargo.toml
-+++ b/deps/tar-0.4.9/Cargo.toml
-@@ -25,7 +25 @@
- tempdir = "0.3"
--
--[target."cfg(unix)".dependencies]
--xattr = { version = "0.1.7", optional = true }
--
--[features]
--default = ["xattr"]
---- a/deps/libgit2-sys-0.6.6/Cargo.toml
-+++ b/deps/libgit2-sys-0.6.6/Cargo.toml
-@@ -20,2 +20,3 @@
- libz-sys = ">= 0"
-+openssl-sys = { version = "0.9", optional = true }
-@@ -26,5 +27,2 @@
--[target."cfg(all(unix, not(target_os = \"macos\")))".dependencies]
--openssl-sys = { version = "0.9", optional = true }
--
- [features]
---- a/deps/git2-0.6.3/Cargo.toml
-+++ b/deps/git2-0.6.3/Cargo.toml
-@@ -22,4 +22,2 @@
- libgit2-sys = { path = "libgit2-sys", version = "0.6.4" }
--
--[target."cfg(all(unix, not(target_os = \"macos\")))".dependencies]
- openssl-sys = { version = "0.9.0", optional = true }
---- a/deps/fs2-0.3.0/Cargo.toml
-+++ b/deps/fs2-0.3.0/Cargo.toml
-@@ -10,3 +10,3 @@
--[target.'cfg(unix)'.dependencies]
-+[dependencies]
- libc = "0.2.2"
---- a/deps/libssh2-sys-0.2.5/Cargo.toml
-+++ b/deps/libssh2-sys-0.2.5/Cargo.toml
-@@ -17,4 +17,2 @@
- libc = "0.2"
--
--[target."cfg(unix)".dependencies]
- openssl-sys = "0.9"
---- a/deps/curl-sys-0.3.6/Cargo.toml
-+++ b/deps/curl-sys-0.3.6/Cargo.toml
-@@ -22,4 +22,2 @@
- libc = "0.2"
--
--[target."cfg(all(unix, not(target_os = \"macos\")))".dependencies]
- openssl-sys = "0.9"
---- a/deps/curl-0.4.1/Cargo.toml
-+++ b/deps/curl-0.4.1/Cargo.toml
-@@ -13,5 +13,2 @@
- curl-sys = { path = "curl-sys", version = "0.3" }
--
--# Unix platforms use OpenSSL for now to provide SSL functionality
--[target."cfg(all(unix, not(target_os = \"macos\")))".dependencies]
- openssl-sys = "0.9.0"
index 91f55488ebb8f38a7d03ddf2a398c94c9f2c8c17..03b84cb453eae0a51f23e5bbf5d7891e7ea22a08 100644 (file)
@@ -1,3 +1,2 @@
 clean-cargo-deps.patch
-deps-adjust.patch
 local-jquery.patch
index f42a32132376c437847bfac62deaed661a56c03c..a2f8ef1a698ee490b4442df56a3ba05949429fce 100755 (executable)
@@ -11,7 +11,7 @@ DEB_HOST_RUST_TYPE := $(call rust_cpu,$(DEB_HOST_GNU_CPU))-unknown-$(DEB_HOST_GN
 DEB_TARGET_RUST_TYPE := $(call rust_cpu,$(DEB_TARGET_GNU_CPU))-unknown-$(DEB_TARGET_GNU_SYSTEM)
 
 # Cargo looks for config in and writes cache to $CARGO_HOME/
-export CARGO_HOME = $(CURDIR)/.cargohome
+export CARGO_HOME = $(CURDIR)/debian/cargohome
 # Ask cargo to be verbose when building
 export VERBOSE = 1
 
@@ -25,8 +25,6 @@ DEPSDIR := $(CURDIR)/deps
 
 override_dh_auto_configure:
        cp -a $(CURDIR)/Cargo.lock $(CURDIR)/.Cargo.lock.orig
-       # Prepare a fake registry by packing all deps
-       ./debian/cargo-vendor-pack.py
 
 override_dh_auto_build:
 ifneq ($(filter stage0,$(DEB_BUILD_PROFILES)),)
@@ -42,12 +40,9 @@ ifneq ($(filter stage0,$(DEB_BUILD_PROFILES)),)
                --host=$(DEB_HOST_RUST_TYPE) \
                --target=$(DEB_TARGET_RUST_TYPE)
        # Workaround for https://github.com/rust-lang/cargo/issues/1423
-       mv $(DEPSDIR) $(CURDIR)/.deps
-       ln -s `find $(CURDIR)/.deps -name 'cargo-*' -type f -executable` $(CURDIR)/cargo-stage0
+       ln -s `find $(DEPSDIR) -name 'cargo-*' -type f -executable` $(CURDIR)/cargo-stage0
 else
        ln -s `which cargo` $(CURDIR)/cargo-stage0
-       # Workaround for https://github.com/rust-lang/cargo/issues/1423
-       mv $(DEPSDIR) $(CURDIR)/.deps
 endif
        # Configure to build cargo using the just-built stage0
        ./configure \
@@ -63,24 +58,19 @@ ifeq (,$(findstring nodoc,$(DEB_BUILD_PROFILES)))
        cd target/doc/ && rm -f jquery.js && ln -s /usr/share/javascript/jquery/jquery.js
 endif
 
-       # Restore from workarounds
-       mv $(CURDIR)/.deps $(DEPSDIR)
-
 override_dh_auto_clean:
        -mv $(CURDIR)/.Cargo.lock.orig $(CURDIR)/Cargo.lock
-       -mv $(CURDIR)/.deps $(DEPSDIR)
        dh_auto_clean
        -$(RM) -r $(CURDIR)/deps/*.rlib \
                        $(CURDIR)/deps/build_script* \
                        $(CURDIR)/deps/cargo* \
                        $(CURDIR)/deps/*.o \
                        $(CURDIR)/target/ \
-                       $(CURDIR)/.cargo/ \
+                       $(CURDIR)/.cargo \
                        $(CURDIR)/config.mk \
                        $(CURDIR)/config.stamp \
                        $(CURDIR)/Makefile \
                        $(CURDIR)/cargo-stage0 \
-                       $(CARGO_HOME) \
                        $(VENDORDIR)
 
 override_dh_auto_install: